package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Conn{

	private static Connection connect = null;
	
	public static Connection getConnect(){
		if(connect()){
		return connect;
		}else{
			System.out.println("Error connect to SQL Server");
		}
		return null;
	}
	public static boolean connect(){
	
	    try {
            Class.forName(Config.driver).newInstance();
            connect = DriverManager.getConnection(
            		Config.url, Config.username, Config.username);
            return true;
        } catch (SQLException ex) {
        	ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }catch (Exception ex){
        	ex.printStackTrace();
        }
	    
        return false;
	}
	
	public static void closeConnect() {
        if (connect != null) {
            try {
                connect.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
    }
}